const express = require('express');
const multer = require('multer');
const morgan = require('morgan');

const app = express();

// 使用 morgan 中间件记录请求日志
app.use(morgan('dev'));

// 配置 multer 中间件
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/');
    },
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
        cb(null, uniqueSuffix + path.extname(file.originalname));
    }
});

const upload = multer({ storage: storage });

// 处理视频上传
app.post('/upload', upload.single('file'), (req, res) => {
    res.status(200).send('文件上传成功');
});

// 启动服务器
const port = 3000;
app.listen(port, () => {
    console.log(`服务器正在监听端口 ${port}`);
});